package com.buding.fx.view;

import com.buding.fx.common.constant.CssStyleInfo;
import com.buding.fx.entity.SystemConfigInfo;
import com.buding.fx.service.SystemInitService;
import javafx.application.Application;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * @author mingdongwei-jwk
 * @date 2022/09/13 18:06
 * @class com.buding.fx.view
 * @Description
 */

public class OnSuccessView extends Application {
    Logger logger = LoggerFactory.getLogger(OnSuccessView.class);

    public  void show(Stage preStage, String useName, String userPhone){
        if (preStage!=null){
            preStage.close();
        }
        SystemInitService pinaManager  = new SystemInitService();
        SystemConfigInfo systemConfigInfo =  pinaManager.initSysConfig();
        logger.info("system config init end !");
        logger.info("*******main pina node init start*******");
        CssStyleInfo css = systemConfigInfo.getCss();
        BorderPane borderPane = new BorderPane();
        borderPane.setPrefWidth(css.getWIGTH());
        borderPane.setPrefHeight(css.getHEIGHT());
        systemConfigInfo.setBorderPane(borderPane);//设置当前的布局父类
        logger.info("border init end, border wight: "+borderPane.getPrefWidth()+"; border height: "+borderPane.getPrefHeight());

        //构建top部分
        Node topNode = pinaManager.getTopNode(systemConfigInfo);
        borderPane.setTop(topNode);
        systemConfigInfo.setTop(topNode);

        //根据上面的节点构建左边的node
        Node leftNode = pinaManager.getLeftNode(topNode,systemConfigInfo);
        borderPane.setLeft(leftNode);
        systemConfigInfo.setLeft(leftNode);

        Node centerNode = pinaManager.getCenter(leftNode,systemConfigInfo);
        borderPane.setCenter(centerNode);
        systemConfigInfo.setCenter(centerNode);

        Scene scene = new Scene(borderPane);
       // button.getStylesheets().add("");
        String css1 = "org/kordamp/bootstrapfx/bootstrapfx.css";
        String css2 = "css/buding-fx-css-main.css";
        scene.getStylesheets().add(css1);
        scene.getStylesheets().add(css2);
        Stage newStage = new Stage();
        newStage.setWidth(css.getWIGTH());
        newStage.setHeight(css.getHEIGHT());
        newStage.setScene(scene);
        newStage.setResizable(true);
        newStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        OnSuccessView onSuccessView = new OnSuccessView();
        onSuccessView.show(primaryStage,"1","1");
    }
}
